<template>
  <el-select v-model="auxiliary" size="small" placeholder="选择" :style="{width:width +'px'}" @change="changeVal">
    <el-option v-for="it in dataList" :key="it.code" :label="it.code + ' ' +it.name" :value="it.id" />
  </el-select>
</template>
<script>
import { getAuxiliary } from '@/api/auxiliary'
export default {
  props: {
    val: {
      type: String,
      default: ''
    },
    code: {
      type: String,
      default: ''
    },
    width: {
      type: Number,
      default: 200
    }
  },
  data() {
    return {
      auxiliary: this.val,
      dataList: []
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      const auxiliaryTypeCode = this.code
      getAuxiliary({ auxiliaryTypeCode }).then((res) => {
        this.dataList = res.data.data || []
      })
    },
    getCode() {
      const obj = this.dataList.find(it => it.id === this.auxiliary)
      return obj && obj.code
    },
    getLabel() {
      const obj = this.dataList.find(it => it.id === this.auxiliary)
      return obj && obj.name
    },
    getUom() {
      const obj = this.dataList.find(it => it.id === this.auxiliary)
      return obj && obj.uom
    },
    changeVal(val) {
      this.$emit('update:val', val)
    }
  }
}
</script>
